package com.edie.customview.data.net;

import android.widget.Toast;

import com.edie.customview.CustomApplication;
import com.edie.customview.data.net.exception.ApiException;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * edie create on 2018/8/15
 */
public abstract class BaseObserver<T> implements Observer<T> {
    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onError(Throwable e) {
        if (e instanceof ApiException) {
            disposeError(((ApiException) e).getCode(), e.getMessage());
        } else {
            e.printStackTrace();
        }
    }

    private void disposeError(int code, String message) {
        switch (code) {
            case 3:
                Toast.makeText(CustomApplication.getmAppContext(), "模拟登陆", Toast.LENGTH_SHORT).show();
                break;
            default:
                Toast.makeText(CustomApplication.getmAppContext(), message, Toast.LENGTH_SHORT).show();
                break;
        }
    }

    @Override
    public void onComplete() {

    }
}
